import { getFormInfo } from "@/api/form";
import { defineStore } from "pinia";
export const useFormStore = defineStore("form", {
  state: () => {
    return {
      formInfo: {
        id: 5,
        createTime: "2024-03-20 13:33:58",
        updateTime: "2024-03-20 13:33:58",
        pid: "7180b3d0-e67b-11ee-84bc-edd03a02e416",
        name: "qweqwe",
        content: [],
        status: false,
        needPassword: 0,
        password: null,
        description: "暂无详情",
        user: {},
        joinUsers: [],
      },
      submitInfo: {},
      pid: "",
      selectComponentIndex: 0,
    };
  },
  getters: {},
  actions: {
    reset() {
      this.formInfo = {
        id: 5,
        createTime: "2024-03-20 13:33:58",
        updateTime: "2024-03-20 13:33:58",
        pid: "7180b3d0-e67b-11ee-84bc-edd03a02e416",
        name: "qweqwe",
        content: [],
        status: false,
        needPassword: 0,
        password: null,
        description: "暂无详情",
        user: {},
        joinUsers: [],
      };
      this.submitInfo = {};
      this.pid = "";
      this.selectComponentIndex = 0;
    },
    async getForm() {
      const data = await getFormInfo(this.pid);
      if (!data.content) {
        data.content = [];
      }
      this.formInfo = data;
      return data;
    },
    selectComponent() {
      return this.formInfo.content[this.selectComponentIndex];
    },
  },
});
